import request from '@/util/axios';
import type {CommonResultType, ListData, PersonsItem, QueryItem, SuccessResultType, resourcesItem, RelatedObjectsItem, CommonQueryItem,} from './type.ts';

export enum API {
  // 获取资产项目列表
  LIST = '/platform-entry/api/asset/project/list',
  //获取详情
  DETAIL = 'http://192.168.43.179:9000/platform-entry/api/asset/project/detail',
  //资产项目添加
  ADD = 'http://192.168.43.179:9000/platform-entry/api/asset/project/create',
  //资产项目删除
  DELETE = 'http://192.168.43.179:9000/platform-entry/api/asset/project/delete',
  //资产项目编辑
  EDIT = 'http://192.168.43.179:9000/platform-entry/api/asset/project/edit',
  //查关联资源
  CHECK_ASSOCIATION = '/platform-entry/api/asset/project/associations',
  //创建关联资源
  CREATE_ASSOCIATION = 'http://27.115.98.190:31060/platform-entry/api/asset/project/create_associations',

  //查资产打包的列表
  PACK_LIST = 'http://27.115.98.190:31060/platform-entry/api/asset/package/list',
  //查资产管理的列表
  MANAGE_LIST = 'http://27.115.98.190:31060/platform-entry/api/asset/resource/list'
}

/**
 * @method  getList 获取资产项目列表
 */
export const getList = (params: QueryItem): Promise<CommonResultType<ListData<PersonsItem>>> => {
  return request.get(API.LIST, { params });
};

/**
 * @method  addProject 添加资产项目
 */
export const addProject = (params: ListData<PersonsItem>): Promise<SuccessResultType<null>> => {
  return request.post(API.ADD, params);
};

/**
 * @method  getDetail 获取资产项目列表详情
 */
export const getDetail = (params: string): Promise<CommonResultType<ListData<PersonsItem>>> => {
  return request.get(`${API.DETAIL}?id=${params}`);
};

/**
 * @method  onDelete 获取资产项目列表详情
 */
export const onDelete = (params: string): Promise<SuccessResultType<null>> => {
  return request.get(`${API.DELETE}?id=${params}`);
};

/**
 * @method  onUpdate 获取资产项目列表
 */
export const onUpdate = (params: ListData<PersonsItem>): Promise<SuccessResultType<null>> => {
  return request.post(API.EDIT, params);
};

/**
 * @method  getRelatedObjects 获取资产项目关联资源
 */
export const getRelatedObjects = (params: string): Promise<SuccessResultType<null>> => {
  return request.get(`${API.CHECK_ASSOCIATION}?id=${params}`);
};

/**
 * @method  createRelatedObjects 添加资产项目关联资源
 */
export const createRelatedObjects = (
  params: RelatedObjectsItem<resourcesItem | any>
): Promise<SuccessResultType<null>> => {
  return request.post(API.CREATE_ASSOCIATION, params);
};

//获取资源打包
export const getAssert = (params: CommonQueryItem) => request.get(API.PACK_LIST, { params });

//获取资源管理
export const getSource = (params: CommonQueryItem) => request.get(API.MANAGE_LIST, { params });
